// pages/subjectDetail/subjectDetail.js
const app = getApp();
const API_URL = 'https://api.lailiaosheji.com/'
import api from '../../utils/api.js';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    subjectList:[]
  },

  goToTest(e){
    wx.navigateTo({
      url: '/pages/subjectTest/subjectTest?paper_category_id=' + e.currentTarget.dataset.paper_category_id + '&name=' + this.data.name,
    })
  },

  goToArticleList(){
    wx.navigateTo({
      url: '/pages/articleList/articleList?paper_category_id=' + this.data.paper_category_id + '&name=' + this.data.name,
    })
  },
  // 请求轮播图片
  getSwiper() {
    api.POST('/applet/RotationChart/finds', {}, res => {
      console.log(res)
      this.setData({
        swiperArr: res.data.data
      })
    })
  },
  //预览轮播图
  previewImage(e) {
    wx.previewImage({
      urls: [API_URL + e.currentTarget.dataset.rotation_chart_url]
    })
  },

  getSubjectList(){
    wx.showLoading({
      title: '加载中',
    })
    api.POST('applet/paperCategory/finds', { second_id: this.data.paper_category_id }, (res) => {
      console.log(res)
      this.setData({
        subjectList: res.data.data
      })
      wx.hideLoading()
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    wx.setNavigationBarTitle({
      title: options.name,
    })
    this.setData({
      paper_category_id: options.paper_category_id,
      name:options.name
    })
    this.getSwiper()
    this.getSubjectList()

    api.POST('applet/ArticleCategory/finds', { paper_category_id: this.data.paper_category_id },          res => {
          console.log(res)
          if(res.data.total){
            this.setData({
              isShowFAZT: true
            })
          }
          
        })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})